export const createYears = () =>{
    const years=[]
    for(let i=1900;i<=2050;i++){
        years.push(i)
    }
    return years
}
export const createMonths = () =>{
    const months=[]
    for(let i=1;i<=12;i++){
        months.push(i)
    }
    return months
}

export const getCurrentDate = () =>{
    const date = new Date()
    return{
        year:date.getFullYear(),
        month:date.getMonth()+1,
        date:date.getDate()
    }
}

export const initList = (year,month) =>{
    const list = []
    // 计算当月一号是周几
    let firstDay = new Date(year,month-1,1).getDay()
    // 周日为0，需转换为7
    if(firstDay === 0){
        firstDay = 7
    }
    // 计算上月
    // 将日期设置为 0 会自动调整到上个月的最后一天
    const lastMonth = new Date(year,month-1,0)
    const lastMonthDays = lastMonth.getDate()

    // 计算当月有多少天(month从0开始,但因为日期设置为0,所以默认可视为month-1)
    const thisMonthdays = new Date(year,month,0).getDate()
    // 填充上月数据
    for(let i=lastMonthDays-firstDay+2;i<=lastMonthDays;i++){
        list.push({type:'last',day:i})
    }
    // 填充当月数据
    for(let i=1;i<=thisMonthdays;i++){
        list.push({type:'this',day:i})
    }
    // 补全下月数据
    const nextMonthDays = 42 - list.length
    // 42-1+thisMonthdays
    for(let i=1;i<=nextMonthDays;i++){
        list.push({type:'next',day:i})
    }
    return list
}